﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLayer
{
    public class Utility
    {
        public static int LoginEmployeeID = 0;

        public static int GetNumber(string str)
        {
            int result = 0;
            int.TryParse(str, out result);
            return result;

        }
        public static string GetDateYYYYMMDD(DateTime? date)
        {
            if (date.HasValue)
                return date.Value.Year.ToString("0000") + "-" + date.Value.Month.ToString("00") + "-" + date.Value.Day.ToString("00");
            else
                return "";
        }
        public static string GetDateToDisplay(DateTime? date)
        {
            if (date.HasValue)
                return date.Value.Day.ToString("00") + "-" + date.Value.Month.ToString("00") + "-" + date.Value.Year.ToString("0000");
            else
                return "";
        }
        public static string GetTimeToDisplay(DateTime? date)
        {
            if (date.HasValue)
                return date.Value.ToShortTimeString();
            else
                return "";
        }
        public static DateTime? GetValidDateElseNull(object date)
        {
            if (date == null)
                return null;
            DateTime dateTime = new DateTime();
            if (DateTime.TryParse(date.ToString(), out dateTime))
            {
                return dateTime;
            }
            else
            {
                return null;
            }
        }

        public static decimal GetNoOfHours(object date1, object date2)
        {
            if (GetValidDateElseNull(date1) == null || GetValidDateElseNull(date2) == null)
                return 0;
            DateTime? firstDate = GetValidDateElseNull(date1);
            DateTime? secondDate = GetValidDateElseNull(date2);
            TimeSpan span = secondDate.Value.Subtract(firstDate.Value);
            return Convert.ToDecimal(span.TotalHours);
        }

        public static DateTime GetDate(string date)
        {
            if (date == "")
            {
                return new DateTime(1900, 01, 01);
            }
            else
            {
                DateTime datetime = new DateTime();
                if (DateTime.TryParse(date, out datetime))
                {
                    return datetime;
                }
                else
                {
                    return new DateTime(1900, 01, 01);
                }
            }
        }


        public enum SalaryEnum
        {
            Basics = 1,
            Deductables = 2,
            OtherIncomes=3,
            TotalSalary=4
        }
        public enum Gender
        {
            Male = 1,
            Female = 2
        }
        public enum MaritalStatus
        {
            Single = 1,
            Married = 2,
            Widow = 3
        }
        public enum EmpStatus
        {
            ACTIVE = 1,
            RESIGNED = 2,
        }
        public enum MonthName
        {
            January = 1,
            February = 2,
            March = 3,
            April= 4,
            May = 5,
            June = 6,
            July = 7,
            August= 8,
            September = 9,
            October = 10,
            November = 11,
            December= 12

        }
    }
}
